"""
+ 合并运算符
支持：字符串,列表,元组
"""
str1 = "合并"
str2 = "运算符"
list1 = [123, 456, 789]
list2 = [321, 654, 987]
tuple1 = (123, 456, 789)
tuple2 = (321, 654, 987)
print(str1 + str2)
print(list1 + list2)
print(tuple1 + tuple2)

"""
* 复制运算符
"""
print(str1 * 10)
print('==' * 10)
print(list1 * 10)
print(tuple1 * 10)

"""
in 和 not in
"""
print("合" in str1)
print("123" in list1)
print("321" in tuple2)
dict1 = {'name': 'python', 'age': 30}
print('name' in dict1)
print('name' in dict1.keys())
print('python' in dict1.values())
print('age' not in dict1.values())

"""
len方法
del方法
"""
print(len(str1))
print(len(list1))
print(len(tuple1))
print(len(dict1))

del (list1[0])
print(list1)
del list1
del (dict1['name'])
print(dict1)

"""
max()
min()
"""
print(max(list2))
print(min(list2))
print(max(tuple1))
print(min(tuple1))

"""
range(start,end,step)
"""
for i in range(1, 10, 1):
    print(i, end=" ")
print()
for j in range(1, 10, 2):
    print(j, end=" ")
print()
for k in range(10):
    print(k, end=" ")
print()

"""
enumerate(可遍历对象,start=0)
"""

list1 = ['a', 'b', 'c', 'd', 'e', 'f']
for i in enumerate(list1):
    print(i, end=' ')
print()

for j in enumerate(list1, start=1):
    print(j, end=' ')
print()

"""
容器类型转换
tuple()
list()
set()
"""
list1 = [10, 20, 30, 40, 50, 20]
s1 = {100, 200, 300, 400, 500}
tuple1 = (10, 20, 30, 40, 50, 20)
print(tuple(list1))
print(tuple(s1))

print(list(s1))
print(list(tuple1))

print(set(list1))
print(set(tuple1))

"""
列表推导式
需求:创建一个0-10的列表
"""
list1 = []
# while实现
i = 0
while i < 10:
    list1.append(i)
    i += 1
print(list1)
# for实现
list2 = []
for i in range(10):
    list2.append(i)
print(list2)
# 列表推导式实现
list3 = [i for i in range(10)]
print(list3)

"""
创建0-10偶数列表
"""
list1 = [i for i in range(0, 10, 2)]
print(list1)
list2 = [i for i in range(10) if i % 2 == 0]
print(list2)

"""
多个for循环实现列表推导式
"""
list1 = [(i, j) for i in range(1, 3) for j in range(3)]
print(list1)

"""
字典推导式
创建一个字典：key是1-5数字,value是这个数组的平方
将两个列表合并成一个字典
提取字典中的目标数据
"""
dict1 = {i: i ** 2 for i in range(1, 5)}
print(dict1)

list1 = ['name', 'age', 'gender']
list2 = ['Tom', 20, 'man']
dict1 = {list1[i]: list2[i] for i in range(len(list1))}
print(dict1)
list1 = ['name', 'age', 'gender', 'id']
list2 = ['Tom', 20, 'man']
dict1 = {list1[i]: list2[i] for i in range(min(len(list1), len(list2)))}
print(dict1)

counts = {'MBP': 268, 'HP': 123, "DELL": 201}
count1 = {key: value for key, value in counts.items() if value >= 200}
print(count1)


"""
集合推导式
"""
list1 = [1, 1, 2]
set1 = {i ** 2 for i in list1}
print(set1)
